<template>
  <div class="login-panel">
    <h1 class="login-title">后台管理系统</h1>
    <el-tabs
      type="border-card"
      v-model="currentTabName"
      class="login-tabs"
      stretch
    >
      <el-tab-pane name="account">
        <template #label>
          <span><i class="el-icon-user"></i> 账号登录</span>
        </template>
        <login-account ref="loginAccountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span><i class="el-icon-mobile-phone"></i> 手机登录</span>
        </template>
        <login-phone ref="loginPhoneRef" />
      </el-tab-pane>
    </el-tabs>
    <div class="form-controll">
      <el-checkbox v-model="isPass">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button @click="handleSubmit" type="primary" class="submit-btn"
      >登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import loginAccount from './login-account.vue'
import loginPhone from './login-phone.vue'
export default defineComponent({
  components: {
    loginAccount,
    loginPhone
  },
  setup() {
    const isPass = ref(true)
    const currentTabName = ref('account')
    const loginAccountRef = ref<InstanceType<typeof loginAccount>>()
    const loginPhoneRef = ref<InstanceType<typeof loginPhone>>()
    // const divRef = ref<HTMLDivElement>()
    const handleSubmit = () => {
      if (currentTabName.value === 'account') {
        loginAccountRef.value?.checkAccount(isPass.value)
      } else {
        loginPhoneRef.value?.checkAccount(isPass.value)
      }
    }
    return {
      isPass,
      handleSubmit,
      loginAccountRef,
      currentTabName,
      loginPhoneRef
    }
  }
})
</script>

<style lang="less" scoped>
.login-panel {
  .login-title {
    text-align: center;
  }
  .login-tabs {
    width: 320px;
  }
  .form-controll {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
  }
  .submit-btn {
    width: 100%;
  }
}
</style>
